<script setup lang="ts">
import {ref, onMounted} from "vue";
import JsonText from "@/components/JsonText.vue";

const props = defineProps({
  modelValue: {type: Object},
  title: {type: String, default: "详情"},
  visible: {type: Boolean, default: false},
})
const emit = defineEmits<{
  (e: "update:visible", visible: boolean): void
}>();
const isVisible = ref(false);
onMounted(() => {
  isVisible.value = props.visible;
})
const close = () => {
  emit("update:visible", false);
}
</script>

<template>
  <div>
    <el-dialog v-model="isVisible" @close="close" top="5%" append-to-body>
      <template #header>
        <div class="json-view-header">
          <span>{{title}}</span>
          <slot name="operation"></slot>
        </div>
      </template>
      <div style="height: 500px;padding: 2px;border: solid 1px var(--el-border-color)">
        <JsonText :value="modelValue"></JsonText>
      </div>
      <template #footer>
        <span class="dialog-footer">
          <slot name="footer"></slot>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<style scoped>
.json-view-header{
  display: flex;
  justify-content: space-between;
  padding-right: 10px;
  justify-items: center;
}
</style>